package view;

import controller.Controller;
import model.DataSource;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class GameJPanel extends JPanel {
    public JButton enterGameJButton;
    public JButton explainGameJButton;
    public JButton stopGameJButton;
    public ExplainGameJPanel explainGameJPanel=new ExplainGameJPanel();
    public StopGameJPanel stopGameJPanel = new StopGameJPanel();
    public MainGamePanel mainGamePanel=new MainGamePanel();



    public  static CardLayout cardLayout=new CardLayout();
    public  static JPanel cardPanel;
    private Controller controller;
    public GameJPanel( Controller controller){
        this.controller=controller;
        setPreferredSize(new Dimension(1200,800));
        setLayout(null);

         cardPanel = new JPanel(cardLayout);
        cardPanel.setBounds(0, 0, 1200, 800);



        mainGamePanel.setLayout(null);
        enterGameJButton = new JButton("进入游戏");
        enterGameJButton.setBounds(503, 250, 150, 60);
        enterGameJButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {

                UI.enterGameJFrame.enterGameJPanel.eastDeZhuField.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.westDeZhuField.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.soutDeZhuField.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.noJaoButton.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.jaoFen1Button.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.jaoFen2Button.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.jaoFen3Button.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.jTextField.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.westTextField.setVisible(false);
                UI.enterGameJFrame.enterGameJPanel.eastTextField.setVisible(false);


                UI.enterGameJFrame.setVisible(true);

                UI.gameJFrame.setVisible(false);
            }
        });


        explainGameJButton = new JButton("游戏介绍");
        explainGameJButton.setBounds(503, 350, 150, 60);
        explainGameJButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cardLayout.show(cardPanel, "游戏介绍");
            }
        });

        stopGameJButton = new JButton("退出游戏");
        stopGameJButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                cardLayout.show(cardPanel, "停止游戏");
            }
        });
        stopGameJButton.setBounds(503, 450, 150, 60);

        mainGamePanel.add(enterGameJButton);
        mainGamePanel.add(explainGameJButton);
      mainGamePanel.add(stopGameJButton);

        cardPanel.add(mainGamePanel, "游戏界面");
        cardPanel.add(stopGameJPanel, "停止游戏");
        cardPanel.add(explainGameJPanel, "游戏介绍");

        add(cardPanel);


    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(DataSource.gameBackGround,0,0,1200,800,null);
    }
}
